home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 260 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: ausnews.austin.ibm.com!hook
  2. From: hook@austin.ibm.com (Gary R. Hook)
  3. Newsgroups: comp.lang.c,comp.os.ms-windows.nt.misc,comp.programming,comp.std.c,comp.unix.aix
  4. Subject: Re: function pointers
  5. Date: 1 Feb 1996 01:37:44 GMT
  6. Organization: AIX Development, IBM Austin
  7. Sender: hook@shocker.austin.ibm.com (Gary R. Hook)
  8. Message-ID: <4ep5h8$2pkk@ausnews.austin.ibm.com>
  9. References: <4eogio$gt0@giga.bga.com>
  10. NNTP-Posting-Host: shocker.austin.ibm.com
  11. X-newsreader: xrn 8.01
  12.  
  13. In article <4eogio$gt0@giga.bga.com>, makuch@bga.com (Michael Makuch) writes:
  14. > The following c code segment compiles and works on
  15. > NT MSVC++ and on SVR4 C compiler, but errors out
  16. > on AIX with a type mismatch;
  17. > struct foostruct1 * myfoo1();
  18. > struct foostruct2 * myfoo2();
  19. > void *(*ptr)();
  20. > ptr = myfoo1;
  21. > [snip]
  22. > ptr = myfoo2;
  23.  
  24. The code is incorrect.  You can only arbitrarily assign to void *
  25. variables; ptr is no such beast.  A cast will work if it is done
  26. correctly:
  27.  
  28.     ptr = (void *(*)()) myfoo1;
  29.  
  30. If you cast back, you'll want something like
  31.  
  32.     struct foostruct1 *(*thisfoo)();
  33.  
  34.     thisfoo = (struct foostruct1 *(*)()) ptr;
  35.  
  36. -- 
  37. ________________________________________________________________________
  38. Gary R. Hook                         | If you have any trouble sounding
  39. AIX Development, RS6000 Division     | condescending, find a Unix user
  40. IBM Corporation, Austin, Texas       | to show you how it's done.
  41. The above opinions are all mine.     | -Scott Adams, author of "Dilbert"
  42.